package com.lagou.edu.service.impl;

import com.lagou.edu.comment.LagouAutoware;
import com.lagou.edu.comment.LagouService;
import com.lagou.edu.comment.LagouTransactional;
import com.lagou.edu.dao.AccountDao;
import com.lagou.edu.dao.impl.JdbcAccountDaoImpl;
import com.lagou.edu.pojo.Account;
import com.lagou.edu.service.TransferService;
import com.lagou.edu.utils.ConnectionUtils;
import com.lagou.edu.utils.TransactionManager;

/**
 * @author 应癫
 */
@LagouService()
public class TransferServiceImpl implements TransferService {

    //private AccountDao accountDao = new JdbcAccountDaoImpl();

    // private AccountDao accountDao = (AccountDao) BeanFactory.getBean("accountDao");

    // 最佳状态
    @LagouAutoware
    private AccountDao accountDao;





    @Override
    @LagouTransactional
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {

        System.out.println(accountDao.testSpringIOC());
            Account from = accountDao.queryAccountByCardNo(fromCardNo);
            Account to = accountDao.queryAccountByCardNo(toCardNo);
            to.setMoney(to.getMoney()+money);
            from.setMoney(from.getMoney()-money);
            accountDao.updateAccountByCardNo(to);
            //int i=1/0;
            accountDao.updateAccountByCardNo(from);
    }
}
